package com.fly.demo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

public class Main2Activity extends AppCompatActivity implements View.OnClickListener {

    private FrameLayout mLayout;
    private LinearLayout layout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        initViews();
    }

    private void initViews() {
        Button button = (Button) findViewById(R.id.main2_btn);
        // mLayout = (FrameLayout) findViewById(R.id.layout);
        layout = (LinearLayout) findViewById(R.id.layout);
        button.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.main2_btn) {
            MyView view = new MyView(Main2Activity.this);
            layout.addView(view);
        }
    }
}
